<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<!--父组件模板-->
<div id="app">
  <cpn :cinfo="info" @itemclick="cpnClick"></cpn>
</div>
<!--子组件模板-->
<template id="cpn">
  <div>
    <button v-for="item in catagories" @click="getId(item)">{{item.name}}</button>
  </div>
</template>
<script src="../js/vue.js"></script>
<script>
  // 子组件
  const cpn = {
    template: '#cpn',
    data() {
      return {
        catagories: [
          {id: 2, name: '热门推荐'},
          {id: 3, name: '家电数码'},
          {id: 4, name: '手机电脑'},
          {id: 5, name: '生活用品'}
        ]
      }
    },
    props: {
      cinfo: {
        info: Object,
        default() {
          return {}
        }
      }
    },
    methods: {
      getId (item) {
        // 自定义事件类型
        this.$emit('itemclick', item)
        // console.log(item);
      }
    }
  }
  // 父组件
  const app = new Vue({
    el: '#app',
    data: {
      message: "你好",
      info: {
        name: 'ehy',
        age: 15,
        height: 1.98
      }
    },
    components: {
      cpn
    },
    methods: {
      cpnClick (item) {
        console.log('cpnClick',item)
      }
    }
  })
</script>
</body>
</html>
